/**
 * @description: 三点确定一个圆
 * @author: fan
 * @date: 2021/10/11:17:20
 * @version: 1.0
 */
public class GetCenter {

    static QPointF tcircle(QPointF pt1, QPointF pt2, QPointF pt3)
    {
        double x1 = pt1.getX(), x2 = pt2.getX(), x3 = pt3.getX();
        double y1 = pt1.getY(), y2 = pt2.getY(), y3 = pt3.getY();
        double a = x1 - x2;
        double b = y1 - y2;
        double c = x1 - x3;
        double d = y1 - y3;
        double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
        double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;
        double det = b * c - a * d;
        if( Math.abs(det) < 1e-5)
        {
           // radius = -1;
            return new QPointF(0,0);
        }

        double x0 = -(d * e - b * f) / det;
        double y0 = -(a * f - c * e) / det;
        // 这是求两点间的距离
        double radius = Math.hypot(x1 - x0, y1 - y0);
        System.out.println(radius);
        return new QPointF(x0, y0);
    }



    public static void main(String[] args) {

        QPointF tcircle = tcircle(new QPointF(1.0, 1.0), new QPointF(1.0, 2.0), new QPointF(3.0, 1.0));
        System.out.println(tcircle);
    }


}
